﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Yuans.BinaryConfig.Utils;

namespace Yuans.BinaryConfig
{
    public class BlobItem : ConfigItem
    {
        private byte[] mBlobValue;
        public byte[] BlobValue
        {
            set
            {
                mBlobValue = value;
                if(mBlobValue!=null)
                {
                    mHash = HashMethod.SuperFastHash(mBlobValue);
                }
                else
                {
                    mHash = 0;
                }
            }

            get
            {
                return mBlobValue;
            }
        }

        private UInt32 mHash;

        public UInt32 Hash
        {
            get { return mHash; }
        }
        public BlobItem(string name, byte[] blob)
        {
            base.ItemName = name;
            base.ItemType = ParamType.BLOB;
            this.BlobValue = blob;
        }
        public override string GetFriendValueDescription()
        {
            return (string.Format("{0}B, HASH:{1:X}", BlobValue.Length,mHash));
        }
        public override byte[] GetItemValueRawBytes()
        {
            return BlobValue;
        }
    }
}
